﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Super_Pong.Classes;
using Game.Classes.Entities.GameEntities;

namespace Super_Pong
{
    /// <summary>
    /// This is the main type for your gamee
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D[] rebatedor;
        Texture2D[] bola;
        Texture2D[] arma;
        Texture2D[] bulletTexture;
        Bar bar;
        Bouncer bouncer;
        Ball ball;
        Weapon gun;
        Weapon gun2;
        Thruster thruster;
        
        
        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
                        
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {            
            spriteBatch = new SpriteBatch(GraphicsDevice);
            rebatedor = new Texture2D[] {Content.Load<Texture2D>(@"Textures/Bouncer")};           
            bola = new Texture2D[] {Content.Load<Texture2D>(@"Textures/Ball") };
            bulletTexture = new Texture2D[] { Content.Load<Texture2D>(@"Textures/bullet") };
            arma = new Texture2D[] { Content.Load<Texture2D>(@"Textures/Weapon") };

            gun = new Weapon(
                Window,
                bar, new Animation(arma, 100L),
                "Balmung Fezalion",
                1,
                gunType.LASER,
                100,
                1,
                new Animation(bulletTexture, 100L),
                new Animation(bulletTexture, 100L),
                "LEFT",
                new Vector2(bulletTexture[0].Width, bulletTexture[0].Height / 2)
                );

            gun2 = new Weapon(
                Window,
                bar, new Animation(arma, 100L),
                "Isaac Schneider",
                0,
                gunType.LASER,
                100,
                1,
                new Animation(bulletTexture, 100L),
                new Animation(bulletTexture, 100L),
                "LEFT",
                new Vector2(bulletTexture[0].Width, bulletTexture[0].Height / 2)
                );

            bouncer = new Bouncer(
                100,
                null,
                Shape.ShapeType.STRAIGHT,
                bouncerType.SHAPE,
                new Animation(rebatedor, 100L),
                new Vector2(0, 0)
                );



            ball = new Ball(new Vector2(60, 60), new Animation(bola,1000000L), 100.0f, 60.0f, 1f, Vector2.Normalize(new Vector2(1.0f, 2.0f)), (bola[0].Width) / 2, Window);
            bar = new Bar(bouncer, gun, gun2, thruster);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            ball.Update(gameTime);           

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Green);

            spriteBatch.Begin();
            ball.Draw(spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
